/**
 * Created by user on 2018/3/20.
 */
const SendRequest = (url, method, data, success, fail, complete) => {
  var xhr = new XMLHttpRequest()
  xhr.open(method, url, true)
  xhr.onreadystatechange = function() {
    if(xhr.readyState == 4) {
      if(xhr.status == 200) {
        let res = {}
        try {
          res = JSON.parse(xhr.response)
          success && success(res)
        } catch(e) {
          fail && fail()
        }
      } else {
        fail && fail()
      }
      complete && complete()
    }
  }
  xhr.send(data)
}
module.exports = {
  SendRequest
}
